package ace.cmp.security.autoconfig;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author caspar
 * @date 2023/2/6 20:09 自动配置通用安全组件
 */
@Slf4j
@Configuration
public class SecurityBootstrapAutoConfigure {
  @Bean
  @ConditionalOnMissingBean
  public PasswordEncoder passwordEncoder() {
    log.info("passwordEncoder");
    DelegatingPasswordEncoder passwordEncoder =
        (DelegatingPasswordEncoder) PasswordEncoderFactories.createDelegatingPasswordEncoder();
    passwordEncoder.setDefaultPasswordEncoderForMatches(
        org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
    return passwordEncoder;
  }
}
